package com.tsky.casing.orm;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * ORM操作接口，封装增、删、改、查等基本功能
 * @author: cainiao
 * @version 1.0 
 * @time: 2010-4-21 下午02:46:50
 */
public interface EntityManager {

	/**
	 * Hibernate save one entity to DataBase
	 * @param entity
	 * @return
	 */
	public boolean saveEntity(Object entity);
	
	/**
	 * Hibernate delete one entity from DataBase
	 * @param classType
	 * @param id
	 * @return
	 */
	public boolean delEntity(Class<?> classType, Object id);
	
	public boolean delEntity(Class<?> classType, Object[] id);
	
	/**
	 * Hibernate update one entity to DataBase
	 * @param entity
	 * @return
	 */
	public boolean updateEntity(Object entity);
	
	/**
	 * Hibernate get one entity from DataBase
	 * @param classType
	 * @param id
	 * @return
	 */
	public <T> T getEntity(Class<T> classType, Object id);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @param classType
	 * @return
	 */
	public <T> List<T> getAllEntity(Class<T> classType);
	
	public <T> List<T> getAllEntity(Class<T> classType, String field, String order);

	/**
	 * Hibernate get some entity(List) from DataBase
	 * @param classType
	 * @return
	 */
	public <T> List<T> getAllEntity(Class<T> classType, int size);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @param classType
	 * @return
	 */
	public <T> List<T> getAllEntity(Class<T> classType, Object status);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @param classType
	 * @return
	 */
	public <T> List<T> getAllEntity(Class<T> classType, Object status, int size);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @author: cainiao
	 * @time: 2010-5-24 上午06:40:38
	 * @function: 
	 * @param classType
	 * @param ids
	 * @return
	 */
	public <T> List<T> getAllEntity(Class<T> classType, Object[] ids);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @author: cainiao
	 * @time: 2010-6-30 上午05:44:40
	 * @function: 
	 * @param classType
	 * @param field
	 * @param value
	 * @return
	 */
	public <T> List<T> getAllEntityByField(Class<T> classType, String field, Object value);
	
	/**
	 * Hibernate get some entity(List) from DataBase
	 * @author: jsfu
	 * @time: 2011-12-12
	 * @function: 
	 * @param classType
	 * @param field
	 * @param value
	 * @param orderfield
	 * @param order
	 * @return
	 */
	public <T> List<T> getAllEntityByField(Class<T> classType, String field, Object value, String orderfield, String order );
	
	/**
	 * 
	 * @function: 通过某字段查询，参数列表为集合(in)
	 * @author: cainiao
	 * @time: 2011-12-15 下午01:35:45
	 * @param <T>
	 * @param classType
	 * @param field
	 * @param values
	 * @return
	 */
	public <T> List<T> getAllEntityByField(Class<T> classType, String field, Object[] values);
	
	/**
	 * 
	 * @function: 通过某字段查询，参数列表为集合(in)
	 * @author: cainiao
	 * @time: 2011-12-28 下午02:56:09
	 * @param <T>
	 * @param classType
	 * @param field
	 * @param values
	 * @return
	 */
	public <T> List<T> getAllEntityByField(Class<T> classType, String field, Collection values);
	
	/**
	 * @function 查询多个字段，参数列表为数组（in）,参数格式为Map<String,Object[]>
	 * @param <T>
	 * @param classType
	 * @param fields
	 * @return
	 */
	public <T> List<T> getAllEntityByField(Class<T> classType, Map<String,Object[]> fields);
	/**
	 * 
	 * @function: 求平均数
	 * @author: cainiao
	 * @time: 2011-10-24 下午01:34:50
	 * @param tableName
	 * @param field
	 * @return
	 */
	public Object avg(String tableName, String field);
}
